package com.class05.m_innerclass.a;

public class Test {
    //    局部内部类
    public static Animal method() {
        class Cat implements Animal {
            @Override
            public void eat() {
                System.out.println("猫吃猫粮");
            }
        }
        return new Cat();
    }
//    匿名内部类
    public static Animal method1(){
       Animal animal = new Animal() {
            @Override
            public void eat() {
                System.out.println("猫吃猫粮");
            }
        };
       return animal;
    }

    public static void method2(Animal animal){
        animal.eat();
    }

    public static Animal method3(){
        return new Animal() {

            @Override
            public void eat() {
                System.out.println("猫吃猫粮");
            }
        };
    }


    public static void main(String[] args) {
        Animal method = method();
        method.eat();
        Animal method1 = method1();
        method1.eat();

        method2(new Animal() {
            @Override
            public void eat() {
                System.out.println("猫吃猫粮");
            }
        });


        method3().eat();

    }
}
